import {
  queryPageList,
  scan,
  add,
  update,
  dbinfodelete,
  testConnection,
  updateLevel,
  queryListByTypeCode,
} from '@/services/sensitiveData/database';

export default {
  namespace: 'database',
  state: {
    // 列表数据
    dataqueryPageList: {
      dataList: [],
      pageNum: 0,
      pageSize: 0,
      totalCount: 0,
    },
  },

  effects: {
    *queryPageList({ payload }, { call, put }) {
      const response = yield call(queryPageList, payload);
      yield put({
        type: 'savequeryPageList',
        payload: response.data || {
          dataList: [],
          pageNum: 0,
          pageSize: 0,
          totalCount: 0,
        },
      });
    },
    *scan({ payload }, { call, put }) {
      const response = yield call(scan, payload);
      return response;
    },
    *add({ payload }, { call, put }) {
      const response = yield call(add, payload);
      return response;
    },
    *update({ payload }, { call, put }) {
      const response = yield call(update, payload);
      return response;
    },
    *dbinfodelete({ payload }, { call, put }) {
      const response = yield call(dbinfodelete, payload);
      return response;
    },
    *testConnection({ payload }, { call, put }) {
      const response = yield call(testConnection, payload);
      return response;
    },
    *updateLevel({ payload }, { call, put }) {
      const response = yield call(updateLevel, payload);
      return response;
    },
    *queryListByTypeCode({ payload }, { call }) {
      const response = yield call(queryListByTypeCode, payload);
      return response;
    },
  },

  reducers: {
    savequeryPageList(state, { payload }) {
      return {
        ...state,
        dataqueryPageList: payload,
      };
    },
  },
};
